#include "graph.h"
#include <iostream>

using namespace std;

graph::graph(int nodeNumber)
{
    graph::pointCount=nodeNumber;
    graph::lineCount=0;
    graph::arr = (Node **)malloc(nodeNumber * sizeof(Node *));
    for (size_t i = 0; i < nodeNumber; i++)
    {
        graph::arr[i] = NULL;
    }
}

graph::~graph()
{
}

Node* graph::newNode(int num, Node *next){
    Node *node = (Node *)malloc(sizeof(Node));
    node->pointNum = num;
    node->next = next;
    return node;
}

void graph::addLink(int node, int target)
{
    graph::arr[node] = graph::newNode(target, graph::arr[node]);
    graph::lineCount++;
}

int graph::echo(int num)
{
    for (size_t i = 0; i < num; i++)
    {
        auto p = graph::arr[i];
        cout << "index:" << i;
        while (p)
        {
            cout << " -> " << p->pointNum ;
            p = p->next;
        }
        cout << endl;
    }
}